//
//  WLLMainViewController.swift
//  WLLWeibo
//
//  Created by 王乐乐 on 16/8/9.
//  Copyright © 2016年 itcast. All rights reserved.
//一些私有都没有设置

import UIKit

class WLLMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //实例化自定义 TabBar
        let tabBar = WLLTabBar()
        tabBar.wllDelegat = self
        //'tabBar' is a get-only property
//        self.tabBar = tabBar
        setValue(tabBar, forKey: "tabBar")
             //MARK: - 添加子子控制器
        
        addChildViewController(WLLHomeViewController(), imageName: "tabbar_home", title: "首页")
        
        addChildViewController(WLLMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        
        addChildViewController(WLLDiscoverViewController(), imageName: "tabbar_discover", title: "发现")
        
        addChildViewController(WLLProfileViewController(), imageName: "tabbar_profile", title: "我")
        
    }
    /**
     *  添加子控制器的封装方法
     */
    func addChildViewController(childController: UIViewController,imageName:String,title:String) {
        //设置 title
        childController.navigationItem.title = title
        childController.tabBarItem.title = title
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        childController.tabBarItem.image = UIImage(named:imageName)
          // AlwaysOriginal 图片渲染方式
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
       
        addChildViewController( UINavigationController(rootViewController: childController))
        
    }
}

extension  WLLMainViewController :WLLTabBarDelegate{
    func tabBarButtonClick(){
        print("撰写按钮的点击")
    //判断是否登录
        if !WLLUserAccountViewModel.shareTool.isLogin {
            print("请登录")
            return
        }
        
        let composeVc = WLLComposeViewController()
        
self.presentViewController(UINavigationController(rootViewController: composeVc), animated: true, completion: nil)
    }
}



